#ifndef TEXTURE2D_H
#define TEXTURE2D_H

#include "BaseTexture.h"

namespace Cvekas {

class TextureManager;

/// Two-dimensional texture
class Texture2D : public BaseTexture
{
public:
	/// Constructor for loading texture from file. You shouldn't construct %Texture2D yourself, TextureManager does this.
	Texture2D(ResourceId id, D3DDevicePtr device, const std::string& name, const std::string& filename, D3DFORMAT format,
		bool pow_of2, bool lockable, bool gen_mipmaps);
    
	/// Constructor for creating empty texture. You shouldn't construct %Texture2D yourself, TextureManager does this.
	Texture2D(ResourceId id, D3DDevicePtr device, const std::string& name, unsigned int width, unsigned int height, 
		D3DFORMAT format, bool gen_mipmaps, bool dynamic);

	/// Constructor for use in RenderTarget, because it sets all the properties itself.
	/// Don't ever use this!
	Texture2D(ResourceId id, D3DDevicePtr device, const std::string& name, D3DFORMAT format) 
		: BaseTexture(id, device, name, format), filename("") 
	{};

	/// Destructor
	virtual ~Texture2D();

    /// Can this texture be locked?
	bool isLockable() const;
	/// Is texture locked?
    bool isLocked() const;
	/// Is texture dynamic?
	bool isDynamic() const;

	/// Locks texture. Throws Exception if texture is already locked.
	/// \param read_only Pass true if no writing to locked buffer will be done, it improves performance.
	LockedTexture lock(bool read_only);
	/// Unlocks locked texture. Throws Exception if texture is not locked.
	void unlock();
        
    /// Returns name of file from which texture was loaded or empty string if texture was not loaded from file.
	const std::string& getFilename() const;

	/// You shouldn't call this
	virtual void onDeviceLost();
	/// You shouldn't call this
	virtual void onDeviceReset();

private:
	void load();
	void create();

protected:
    bool is_locked;
	bool is_lockable;
	bool is_dynamic;
    
	const std::string filename;

	uint width;
	uint height;
	uint mipmaps;
	DWORD usage;

};

typedef boost::shared_ptr<Texture2D> Texture2DPtr;

} // namespace

#endif